# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.ods.log.es_login_log import jms_ods__es_login_log

jms_dwd__dwd_sys_es_login_log_dt = SparkSqlOperator(
    task_id='jms_dwd__dwd_sys_es_login_log_dt',
    pool_slots=2,
    master='yarn',
    email=['rabie.zhuang@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dwd__dwd_sys_es_login_log_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/sys/dwd_sys_es_login_log_dt/execute.hql',
    executor_cores=2 , 
    executor_memory='1G' , 
    num_executors=2 , 
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled' : 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 2 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode' : 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '1G' , 
          'spark.sql.shuffle.partitions'  : 400,
    },
    hiveconf={'hive.exec.dynamic.partition' : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode' : 'nonstrict',
              'hive.exec.max.dynamic.partitions' : 400,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 400,  # 每天生成 20 个分区
    },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=30),
)

jms_dwd__dwd_sys_es_login_log_dt << [
    jms_ods__es_login_log
]
